﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PWMIS.DataMap.Entity;
using FTchina.Models;
using FTchina.Library;
namespace FTchina.Logic
{
    /// <summary>
    ///LoginLogic 的摘要说明
    /// </summary>
    public class LoginLogic
    {
        public LoginLogic()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }


        /// <summary>
        /// 验证机器人代码是否正确
        /// </summary>
        /// <returns></returns>
        public static Boolean RobotLogin()
        {
            return (RequestHelper.GetRequst("ROBOTKEY") == System.Configuration.ConfigurationManager.AppSettings["ROBOTKEY"].ToString());

        }

        /// <summary>
        /// 通过部门名称获取BSSAreaCode
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static string GetBssAreaCodeByName(string name, out string Area_Name)
        {
            Area_Name = string.Empty;
            string tmp = string.Empty;

            FTchina.Models.RelationList mRelationList = new FTchina.Models.RelationList();

            //拼接查询条件
            OQLCompare cmp = new OQLCompare(mRelationList);
            OQLCompare cmpResult = (cmp.Comparer(mRelationList.Name, OQLCompare.CompareType.Equal, name));

            OQL q = new OQL(mRelationList);
            q.Select().Where(cmpResult).OrderBy(mRelationList.Id, "desc");//按条件查询条件
            List<FTchina.Models.RelationList> list = EntityQuery<FTchina.Models.RelationList>.QueryList(q, mRelationList);
            foreach (FTchina.Models.RelationList item in list)
            {
                tmp += "'" + item.AREA_CODE + "',";
                Area_Name = item.AREA_NAME;//分公司名称
            }
            tmp = tmp.TrimEnd(',');

            return tmp;
        }



        /// <summary>
        /// 获取用户的角色信息
        /// </summary>
        /// <param name="UserGroupID"></param>
        /// <returns></returns>
        public static string GetUserGroupNameByID(string UserGroupID)
        {
            /////角色信息
            UserGroup ug = new UserGroup();

            OQLCompare cmp = new OQLCompare(ug);
            OQLCompare cmpResult = (cmp.Comparer(ug.Id, OQLCompare.CompareType.IN, UserGroupID));

            OQL q = new OQL(ug);
            q.Select().Where(cmpResult).OrderBy(ug.Id, "desc");//按条件查询条件

            List<UserGroup> list = EntityQuery<UserGroup>.QueryList(q, ug);

            string tmp = string.Empty;
            foreach (UserGroup ux in list)
            {
                tmp += ux.Groupname + ",";
            }
            return tmp.TrimEnd(',');
        }
    }
}